function collect(item){
	$.ajax({
		type:'POST',
		url:'file/collect_item.action',
		data:{'itemID':item},
		success:collectCall,
		dataType:'json'
	});
}

function collectCall(data){
	if (data['success'] == "success"){
		$("#collect_item").hide();
		$("#del_collect").show();
	}
}

function del_collect(item){
	$.ajax({
		type:'POST',
		url:'file/del_collect.action',
		data:{'itemID':item},
		success:delCollectCall,
		dataType:'json'
	});
}

function delCollectCall(data){
	if (data['success'] == "success"){
		$("#collect_item").show();
		$("#del_collect").hide();
	}
}
function setGrade(a){
	var list = $("#rateStar").children();
	for (i = 0; i < list.length; i++){
		if (a <= i){ 
			list[i].className = "grade icon star-big-off";
			}
		if (a > i && a < i + 1){
			list[i].className = "grade icon star-big-half";
		}
		if (a >= i + 1){
			list[i].className = "grade icon star-big-on";
		}
	}
}
function gradeItemCall(data){
	isGrade = true;
	grade = data['grade'];
	setGrade(grade);
	$("#rateCount").text(data['gradeNum']);
	$("#rateScore").text(grade);
	$("#rateTip").text("谢谢评价");
	$("#rateTip").show();
	$("#rateTip").fadeOut();
}

$(document).ready(function (){
	$(".grade").click(function(){
		
		if (isGrade || !isLogin)
			return;
		var param = {'itemID':$("#id_itemID").val(),'grade':this.getAttribute("grade")};
		$.ajax({
			type:'POST',
			url:'file/grade_item.action',
			data:param,
			success:gradeItemCall,
			dataType:'json'
	});
		
	});
	$(".grade").mouseenter(function(){
		if (isGrade || !isLogin)
			return;
		setGrade(this.getAttribute("grade"));
	});
	$(".grade").mouseleave(function(){
		if (isGrade || !isLogin)
			return;
		setGrade(grade);
	});
	
	$(".delComm").click(function(){
		$.ajax({
			type:'POST',
			url:'file/grade_item.action',
			data:param,
			success:gradeItemCall,
			dataType:'json'
		});
	});
});